<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleleaf.org">
<head th:insert="base">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="/back/welcome">首页</a>
            <a href="#">权限管理</a>
            <a>
              <cite>系统资源</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <table class="layui-hide" id="tableId" lay-filter="tableId"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn" lay-event="addPermission"><i class="layui-icon layui-icon-add-1"></i>添加</button>
    </div>
</script>
<script type="text/html" id="operations">
    <a lay-event="edit" class="layui-btn layui-btn-xs" title="编辑">编辑</a>
    <a lay-event="del" class="layui-btn layui-btn-xs layui-btn-danger" title="删除">删除</a>
</script>
<script th:inline="none">
    layui.use(['table','util','treetable','tool'], function(){
        var table = layui.table;
        var $ = layui.jquery;
        var util = layui.util;
        var treetable = layui.treetable;
        var tool = layui.tool;
        var baseUrl = "/back/permission";

        treetable.render({
            elem: '#tableId'
            ,id:'tableReload'
            ,url:'/back/permission/getList'
            ,treeColIndex: 1    //树形图标显示在第几列
            ,treeSpid: "0"
            ,treeIdName: 'id'
            ,treePidName: 'treePid'
            ,toolbar:'#toolbar'
            ,defaultToolbar: ['print']
            ,title: '系统权限表'
            ,cols: [[
                {field: '', title: '序号',width:50,type:'numbers'}
                ,{field:'permissionName', title:'权限名称',width:250,type: 'text'}
                ,{field:'permissionCode', title:'权限代码',width:200,type: 'text'}
                ,{field:'permissionUrl', title:'Url',width:200,type: 'text'}
                ,{field:'permissionTypeDesc', title:'权限类型',width:130,type: 'text'}
                ,{field:'createTime', title:'创建时间',width:180,type: 'text',templet:function (d) {
                        if(d.createTime){
                            return util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss")
                        }
                        return "";
                    }}
                ,{title:'操作',width:200, toolbar: '#operations'}
            ]]
            ,page: false
        });

        //头工具栏事件
        table.on('toolbar(tableId)', function(obj){
            switch(obj.event){
                case 'addPermission':
                    xadmin.open('添加资源',baseUrl + '/add');
                    break;
            }
        });
        //行工具栏事件
        table.on('tool(tableId)', function(obj){
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    layer.confirm('确认删除此权限？', function(index){
                        var res = tool.submit(baseUrl + '/delete',{id:data.id});
                        if(res.code == return_200){
                            layer.msg(res.msg, {
                                    icon: msg.success,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }else {
                            layer.msg(res.msg, {
                                    icon: msg.error,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }
                    });
                    break;
                case 'edit':
                    xadmin.open('编辑权限',baseUrl + '/edit?id='+data.id);
                    break;
            }
        });

        /**
         * 回调函数
         */
        function callBack() {
            location.reload()
        }

    });
</script>
</body>
</html>